<template>
  <view>
    <!-- 自定义搜索框 -->
    
    <!-- 分类搜索 -->
    <view class="scroll-view-container">
      <!-- 左侧一级分类 -->
      <scroll-view class="left-scroll-view" scroll-y="true" :style="{height: wh+'px'}">
        <view 
          :class="['left-scroll-view-item', i===active ? 'active': '']"
          v-for="(item, i) in cateList"
          :key="i"
          @click="changeActive(i)"
        >
          {{item.cat_name}}
        </view>
      </scroll-view>
      <!-- 右侧二级分类 -->
      <scroll-view class="right-scroll-view" scroll-y="true" >
        <view>二级分类</view>
        <view>二级分类</view>
      </scroll-view>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        wh: 0, // 屏幕可用高度
        active: 0, // 选中一级分类索引
        cateList: [], // 分类数据
      };
    },
    onLoad() {
      // 获取屏幕可用高度
      const sysInfo = uni.getSystemInfoSync()
      this.wh = sysInfo.windowHeight
      console.log('wh', this.wh)
      // 获取分类数据
      this.getCateList()
    },
    methods: {
      // 获取分类数据
      async getCateList(){
        const {data:res} = await uni.$http.get('/categories')
        console.log(res)
        // 一场判断
        if(res.meta.status !== 200) return uni.$showMsg()
        
        // 赋值数据到data中
        this.cateList = res.message
      },
      
      // 改变一级分类索引
      changeActive(i){
        this.active = i
      }
    }
  }
</script>

<style lang="scss">
  .scroll-view-container{
    display: flex;
    .left-scroll-view{
      width: 240rpx;
      background-color: #efefef;
      .left-scroll-view-item {
        height: 120rpx;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 24rpx;
        &.active {
          background-color: #ffffff;
          display: flex;
          justify-content: space-between;
          &::before {
            content: '';
            width: 6rpx;
            height: 60rpx;
            background-color: #c00000;
          }
          &::after {
            content: '';
            width: 6rpx;
            height: 60rpx;
            background-color: #ffffff;
          }
        }
      }
    }
  }
</style>
